package com.play;

import java.util.Random;

public  class Game extends LevelParam{
    private Player player;

    public Game(Player player) {
        this.player = player;
    }

    public  String printStr(){
        int strLength = LevelParam.levels[player.getLevelNo()-1].getStrLength();
        Random random = new Random();
        StringBuffer buffer =new StringBuffer();
        for (int i = 0; i < strLength; i++) {
            int rand = random.nextInt(strLength); // 产生随机数
            // 根据随机数拼接字符串
            switch (rand) {
                case 0:
                    buffer.append(">");
                    break;
                case 1:
                    buffer.append("<");
                    break;
                case 2:
                    buffer.append("*");
                    break;
                case 3:
                    buffer.append("!");
                    break;
                case 4:
                    buffer.append("@");
                    break;
                case 5:
                    buffer.append("%");
                    break;
                case 6:
                    buffer.append("^");
                    break;
            }
        }
        System.out.println(buffer);
        return buffer.toString();
    }
    public  void printResult(String out,String in){
        if (out.equals(in)){
            long currentTime = System.currentTimeMillis();
            if ((currentTime - player.getStartTime())/10000 >
                    LevelParam.levels[player.getLevelNo() - 1].getTimeLimit()){
                System.out.println("你输入的太慢,已经超时,退出!");
                System.exit(0);
            }else{
                //计算玩家当前积分
                player.setCurScore(player.getCurScore()
                        + LevelParam.levels[player.getLevelNo() - 1].getPerScore());
                //计算消耗时间
                player.setElapsedTime((int)(currentTime - player.getStartTime())/10000);
                System.out.println("输入正确,您的级别是:" + player.getLevelNo() +
                        ",您当前的积分为:" + player.getCurScore() + "分,您所用时间为:"
                        + player.getElapsedTime() + "秒");
            }
        }else{
            System.out.println("输入错误,退出!");
            System.exit(0);
        }
    }
}
